package operator;

import org.apache.flink.api.common.typeinfo.TypeInformation;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.operators.AbstractStreamOperator;
import org.apache.flink.streaming.api.operators.OneInputStreamOperator;
import org.apache.flink.streaming.runtime.streamrecord.StreamRecord;

/**
 * Flink的Filter 算子
 */
public class FilterDemo {

    public static void main(String[] args) throws Exception {
        // Flink配置
        Configuration conf = new Configuration();
        conf.setInteger("rest.port", 80);
        // 创建带Webui的Flink本地执行环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.createLocalEnvironmentWithWebUI(conf);
        // 使用socket创建DataStream
        DataStreamSource<String> data = env.socketTextStream("192.168.56.10", 8888);

        SingleOutputStreamOperator<Integer> filtered = data.map(Integer::parseInt).filter(x -> x % 2 == 0);

        // sink
        filtered.print();

        env.execute("map operator");
    }


}
